package user

import "fmt"

type House struct {
	Name  string
	Users []*User
	C     chan string
}

func NewHouse(name string, users []*User) *House {
	house := &House{
		Name:  name,
		Users: users,
		C:     make(chan string),
	}
	go house.listenMessage()
	house.C <- fmt.Sprintf("%s:%s", "server", "你已加入群聊:["+name+"],创建人:["+users[0].Host+"]")
	for i := range users {
		users[i].AddHouse(house)
	}
	return house
}

func (h *House) listenMessage() {
	for {
		msg := <-h.C
		for i := range h.Users {
			h.Users[i].C <- msg
		}
	}
}
